<html>
    <head>
        <script type="text/javascript">
            <?php
                if($this->id == ""){
                    ?>
                    common.setMainTitle("Add New Product");
                    <?php
                }else{
                    ?>
                    common.setMainTitle("Edit Product");
                    <?php
                }
            ?>
        </script>
        <meta http-equiv = "Content-Type" content="text/html; charset=utf-8"/>
        <link rel="stylesheet" href="/js/fileuploader/fileuploader.css" type="text/css" media="screen" title="default" />
	<script src="/js/fileuploader/fileuploader.min.js" type="text/javascript"></script> 
    </head>

    <body style="background-color: transparent ">
        <form id="id-form" name="frm" method="post" action="/admin/product/save">
            <table>
                <tr>
                    <td nowrap="nowrap"> Name </td>
                    <td>
                        <input type="hidden" name="PRODUCTID" value="<?=$this->id ?>" />
                        <input class="" id="name" name="NAME" value="<?=(isset($this->data->NAME) ? $this->data->NAME : "")?>" type="text" size="50" maxlength="75"/>
                    </td>
                </tr>
                
                <tr>
                    <td> Image</td>
                    <td>
                        <!-- <input type="file" name="IMAGEURL" value=""/> -->
                        <div id="file-uploader-logo">		
                            <noscript>			
                                    <p>Please enable JavaScript to use file uploader.</p>
                                    <!-- or put a simple form for upload here -->
                            </noscript>         
                        </div>
                        <img id="img-product" name="imgProduct" src="<?=(isset($this->data->IMAGEURL) ? $this->data->IMAGEURL : "")?>">
                        <input type="hidden" name="IMAGEURL" value="<?=(isset($this->data->IMAGEURL) ? $this->data->IMAGEURL : "")?>" id="imageurlSave"/>
                    </td>
                </tr>
                
                <tr>
                    <td>Description</td>
                    <td>
                        <textarea name="DESCRIPTION" cols="50" rows="5"><?=(isset($this->data->DESCRIPTION) ? $this->data->DESCRIPTION : "")?></textarea>
                    </td>
                </tr>
                
                <tr>
                    <td>Price</td>
                    <td>
                        <input name="PRICE" value="<?=(isset($this->data->PRICE) ? $this->data->PRICE : 0)?>"/>
                    </td>
                </tr>
                
                <tr>
                    <td>Category</td>
                    <td>
                        <select name="PRODUCTCATEGORYID">
                            <?php
                                $selected = "";
                                foreach($this->listCategories as $category){
                                    if($category['PRODUCTCATEGORYID'] == $this->data->PRODUCTCATEGORYID){
                                        $selected ="selected=''";
                                    }else{
                                        $selected = "";
                                    }
                                    ?>
                                    <option <?=$selected?> value="<?=$category['PRODUCTCATEGORYID']?>"><?=$category['NAME']?></option>
                                    <?php
                                }
                            ?>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <td colspan="2" align="center">
                        <input type="reset" value="Cancel"/>
                        <input type="submit" value="Save" />
                    </td>
                </tr>
            </table>
        </form>
        <script type="text/javascript">
            var logo = new qq.FileUploader({
                element: document.getElementById('file-uploader-logo'),
                action: '/admin/product/upload',
                onComplete: function(id, fileName, responseJSON){
                    fileName = responseJSON['fileName'];
                    //alert(fileName);
                    $(".qq-upload-list").remove();
                    imageURL = "<?php echo $this->baseURL();?>/upload/store/"+$.trim(fileName);
                    //$("#imageDisplaylogo").remove();
                    //$("#file-uploader-logo").find(".qq-upload-button").after("<img width='120' height='120' name='imageDisplaylogo' id='imageDisplaylogo' src='<?php echo $this->baseURL();?>/upload/store/"+$.trim(fileName)+ "' alt='Picture here'/>");
                    $("#img-product").attr("src",imageURL);
                    $("#imageurlSave").val(imageURL);
                }
                
                });
        </script>
    </body>
</html>